<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>~/alphaworks/testes/thread-capacity-web/src/java/br/com/claudius/threads/ServletTest.java.html</title>
<meta name="Generator" content="Vim/7.1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#000000" text="#ffffff"><font face="monospace">
<font color="#ffff00"><b>&nbsp;1 </b></font><br>
<font color="#ffff00"><b>&nbsp;2 </b></font><font color="#8080ff"><b>package</b></font>&nbsp;br.com.claudius.threads;<br>
<font color="#ffff00"><b>&nbsp;3 </b></font><br>
<font color="#ffff00"><b>&nbsp;4 </b></font><font color="#8080ff"><b>import</b></font>&nbsp;java.io.*;<br>
<font color="#ffff00"><b>&nbsp;5 </b></font><br>
<font color="#ffff00"><b>&nbsp;6 </b></font><font color="#8080ff"><b>import</b></font>&nbsp;javax.servlet.*;<br>
<font color="#ffff00"><b>&nbsp;7 </b></font><font color="#8080ff"><b>import</b></font>&nbsp;javax.servlet.http.*;<br>
<font color="#ffff00"><b>&nbsp;8 </b></font><br>
<font color="#ffff00"><b>&nbsp;9 </b></font><font color="#00ff00"><b>public</b></font>&nbsp;<font color="#00ff00"><b>class</b></font>&nbsp;ServletTest <font color="#00ff00"><b>extends</b></font>&nbsp;HttpServlet <font color="#00ffff"><b>{</b></font><br>
<font color="#ffff00"><b>10 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<br>
<font color="#ffff00"><b>11 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font color="#00ff00"><b>protected</b></font><font color="#00ffff"><b>&nbsp;</b></font><font color="#00ff00"><b>void</b></font><font color="#00ffff"><b>&nbsp;processRequest(HttpServletRequest request, HttpServletResponse response)</b></font><br>
<font color="#ffff00"><b>12 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00"><b>throws</b></font>&nbsp;ServletException, IOException <font color="#00ffff"><b>{</b></font><br>
<font color="#ffff00"><b>13 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.setContentType(<font color="#ff40ff"><b>&quot;text/html;charset=UTF-8&quot;</b></font>);<br>
<font color="#ffff00"><b>14 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
<font color="#ffff00"><b>15 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff40ff"><b>String</b></font>&nbsp;num = request.getParameter(<font color="#ff40ff"><b>&quot;num_threads&quot;</b></font>);<br>
<font color="#ffff00"><b>16 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00"><b>if</b></font>&nbsp;(num != <font color="#ff40ff"><b>null</b></font>&nbsp;&amp;&amp; num.trim().length()&nbsp;&gt; <font color="#ff40ff"><b>0</b></font>)&nbsp;<font color="#00ffff"><b>{</b></font><br>
<font color="#ffff00"><b>17 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumThreads.CR = <font color="#ff40ff"><b>&quot;&lt;br&gt;&quot;</b></font>;<br>
<font color="#ffff00"><b>18 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumThreads.psout = <font color="#ffff00"><b>new</b></font>&nbsp;PrintStream(response.getOutputStream());<br>
<font color="#ffff00"><b>19 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumThreads.print(<font color="#ff40ff"><b>&quot;&lt;html&gt;&lt;body&gt;&quot;</b></font>);<br>
<font color="#ffff00"><b>20 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00"><b>try</b></font>&nbsp;<font color="#00ffff"><b>{</b></font><br>
<font color="#ffff00"><b>21 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumThreads.main(<font color="#ffff00"><b>new</b></font>&nbsp;<font color="#ff40ff"><b>String</b></font>[]<font color="#00ffff"><b>{</b></font>num<font color="#00ffff"><b>}</b></font>);<br>
<font color="#ffff00"><b>22 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
<font color="#ffff00"><b>23 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>}</b></font>&nbsp;<font color="#ffff00"><b>catch</b></font>&nbsp;(<font color="#ffff00"><b>Exception</b></font>&nbsp;ex)&nbsp;<font color="#00ffff"><b>{</b></font><br>
<font color="#ffff00"><b>24 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ex.printStackTrace();<br>
<font color="#ffff00"><b>25 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>}</b></font><br>
<font color="#ffff00"><b>26 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumThreads.print(<font color="#ff40ff"><b>&quot;&lt;/body&gt;&lt;/html&gt;&quot;</b></font>);<br>
<font color="#ffff00"><b>27 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>}</b></font><br>
<font color="#ffff00"><b>28 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>}</b></font><br>
<font color="#ffff00"><b>29 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<br>
<font color="#ffff00"><b>30 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>// &lt;editor-fold defaultstate=&quot;collapsed&quot; desc=&quot;HttpServlet methods. Click on the + sign on the left to edit the code.&quot;&gt;</b></font><br>
<font color="#ffff00"><b>31 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>/**</b></font><font color="#ff6060"><b>&nbsp;Handles the HTTP </b></font><font color="#00ffff"><b>&lt;</b></font><font color="#ffff00"><b>code</b></font><font color="#00ffff"><b>&gt;</b></font><font color="#ff6060"><b>GET</b></font><font color="#00ffff"><b>&lt;/</b></font><font color="#ffff00"><b>code</b></font><font color="#00ffff"><b>&gt;</b></font><font color="#ff6060"><b>&nbsp;method.</b></font><br>
<font color="#ffff00"><b>32 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp; * </b></font><font color="#ff6060"><b>@param</b></font><font color="#00ffff"><b>&nbsp;request</b></font><font color="#00ffff"><b>&nbsp;servlet request</b></font><br>
<font color="#ffff00"><b>33 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp; * </b></font><font color="#ff6060"><b>@param</b></font><font color="#00ffff"><b>&nbsp;response</b></font><font color="#00ffff"><b>&nbsp;servlet response</b></font><br>
<font color="#ffff00"><b>34 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp; */</b></font><br>
<font color="#ffff00"><b>35 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font color="#00ff00"><b>protected</b></font><font color="#00ffff"><b>&nbsp;</b></font><font color="#00ff00"><b>void</b></font><font color="#00ffff"><b>&nbsp;doGet(HttpServletRequest request, HttpServletResponse response)</b></font><br>
<font color="#ffff00"><b>36 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00"><b>throws</b></font>&nbsp;ServletException, IOException <font color="#00ffff"><b>{</b></font><br>
<font color="#ffff00"><b>37 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;processRequest(request, response);<br>
<font color="#ffff00"><b>38 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>}</b></font><br>
<font color="#ffff00"><b>39 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<br>
<font color="#ffff00"><b>40 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>/**</b></font><font color="#ff6060"><b>&nbsp;Handles the HTTP </b></font><font color="#00ffff"><b>&lt;</b></font><font color="#ffff00"><b>code</b></font><font color="#00ffff"><b>&gt;</b></font><font color="#ff6060"><b>POST</b></font><font color="#00ffff"><b>&lt;/</b></font><font color="#ffff00"><b>code</b></font><font color="#00ffff"><b>&gt;</b></font><font color="#ff6060"><b>&nbsp;method.</b></font><br>
<font color="#ffff00"><b>41 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp; * </b></font><font color="#ff6060"><b>@param</b></font><font color="#00ffff"><b>&nbsp;request</b></font><font color="#00ffff"><b>&nbsp;servlet request</b></font><br>
<font color="#ffff00"><b>42 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp; * </b></font><font color="#ff6060"><b>@param</b></font><font color="#00ffff"><b>&nbsp;response</b></font><font color="#00ffff"><b>&nbsp;servlet response</b></font><br>
<font color="#ffff00"><b>43 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp; */</b></font><br>
<font color="#ffff00"><b>44 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font color="#00ff00"><b>protected</b></font><font color="#00ffff"><b>&nbsp;</b></font><font color="#00ff00"><b>void</b></font><font color="#00ffff"><b>&nbsp;doPost(HttpServletRequest request, HttpServletResponse response)</b></font><br>
<font color="#ffff00"><b>45 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ff00"><b>throws</b></font>&nbsp;ServletException, IOException <font color="#00ffff"><b>{</b></font><br>
<font color="#ffff00"><b>46 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;processRequest(request, response);<br>
<font color="#ffff00"><b>47 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>}</b></font><br>
<font color="#ffff00"><b>48 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<br>
<font color="#ffff00"><b>49 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>/**</b></font><font color="#ff6060"><b>&nbsp;Returns a short description of the servlet.</b></font><br>
<font color="#ffff00"><b>50 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp; */</b></font><br>
<font color="#ffff00"><b>51 </b></font><font color="#00ffff"><b>&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font color="#00ff00"><b>public</b></font><font color="#00ffff"><b>&nbsp;</b></font><font color="#ff40ff"><b>String</b></font><font color="#00ffff"><b>&nbsp;getServletInfo()</b></font>&nbsp;<font color="#00ffff"><b>{</b></font><br>
<font color="#ffff00"><b>52 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ffff00"><b>return</b></font>&nbsp;<font color="#ff40ff"><b>&quot;Short description&quot;</b></font>;<br>
<font color="#ffff00"><b>53 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>}</b></font><br>
<font color="#ffff00"><b>54 </b></font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#00ffff"><b>// &lt;/editor-fold&gt;</b></font><br>
<font color="#ffff00"><b>55 </b></font><font color="#00ffff"><b>}</b></font><br>
</font></body>
</html>
